package com.sgb.kjwl.view.ui.fragment.enterprise;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.config.PictureMimeType;
import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.kjwl.AppFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentCompanyPublishBinding;
import com.sgb.kjwl.model.entity.enterprise.IpPickSelectEntity;
import com.sgb.kjwl.model.entity.enterprise.PublishCompanyDetailEntity;
import com.sgb.kjwl.model.entity.enterprise.RegisterAddr;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.utils.ActivityJump;
import com.sgb.kjwl.utils.KeyboardUtils;
import com.sgb.kjwl.utils.PickerHelper;
import com.sgb.kjwl.utils.PointUtils;
import com.sgb.kjwl.utils.UploadCheckHelper;
import com.sgb.kjwl.view.ui.activity.enterprise.MakeOverPublishActivity;
import com.sgb.kjwl.view.ui.activity.enterprise.MakeOverPublishMainActivity;
import com.swgk.core.view.CityPickBuilder;
import com.swgk.core.view.CityPickView;
import com.sgb.kjwl.viewmodel.enterprise.PublishViewModel;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CompanyPublishFragment extends AppFragment {

    FragmentCompanyPublishBinding mBinding;
    PublishViewModel mViewModel;
    private PublishCompanyDetailEntity mEntity;
    private String mId = "",mEnterpriseType,mIndustry,mIndustryName,mProvince,mProvinceName,mCity,mCityName,mArea,mAreaName,mTaxReturns,mStrTaxReturns,mTaxScale,mCategory,mCategoryName;
    private String mTime;
    OptionsPickerView<IpPickSelectEntity> mEnterpriseTypeOptionsPickerView, mIndustryTypeOptionsPickerView,mModelOptionsPickerView;
    private CityPickView mCityPickView;
    private int op1,op2,op3;
    private List<File> list = new ArrayList<>();
    private String mImage = "";
    private MakeOverPublishActivity mActivity;
    private boolean isChecked,isCheck,isCheckNo;
    private  int mStatus;

    public static CompanyPublishFragment newInstance(){
        CompanyPublishFragment tradePublishFragment = new CompanyPublishFragment();
        return tradePublishFragment;
    }

    public static CompanyPublishFragment newInstance(PublishCompanyDetailEntity entity){
        CompanyPublishFragment tradePublishFragment = new CompanyPublishFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("entity",entity);
        tradePublishFragment.setArguments(bundle);
        return tradePublishFragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_company_publish,container,false);
        return mBinding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mBinding.setLifecycleOwner(this);
        mViewModel = new ViewModelProvider(this).get(PublishViewModel.class);

        initEditView();
        initCheckBox();
        initButton();
        initData();
    }

    private void initEditView() {
        mBinding.etFragmentCompanyPublishRegister.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence str, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                String s = editable.toString();
                mBinding.etFragmentCompanyPublishRegister.removeTextChangedListener(this);

                if (s.contains(".")) {
                    mBinding.etFragmentCompanyPublishRegister.setFilters(new InputFilter[]{new InputFilter.LengthFilter(9 + 2 + 1)});
                    if (s.length() - 1 - s.indexOf(".") > 2) {
                        s = s.substring(0,
                                s.indexOf(".") + 2 + 1);
                        editable.replace(0, editable.length(), s.trim());
                    }
                } else {
                    mBinding.etFragmentCompanyPublishRegister.setFilters(new InputFilter[]{new InputFilter.LengthFilter(9 + 1)});
                    if (s.length() > 9) {
                        s = s.substring(0, 9);
                        editable.replace(0, editable.length(), s.trim());
                    }
                }
                if (s.trim().equals(".")) {
                    s = "0" + s;
                    editable.replace(0, editable.length(), s.trim());
                }

                if (s.startsWith("0") && s.trim().length() > 1) {
                    if (!s.startsWith(".", 1)) {
                        editable.replace(0, editable.length(), "0");
                    }
                }
                mBinding.etFragmentCompanyPublishRegister.addTextChangedListener(this);
            }
        });

    }

    private void initCheckBox(){
        mBinding.deleteTv.setVisibility(View.GONE);

        mBinding.rbFragmentCompanyPublishMakeoverSelectorPrice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isChecked = !isChecked;
                if (isChecked){
                    mBinding.ivYijia.setImageResource(R.mipmap.gouxuan_makeover_publish_price);
                    mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setEnabled(false);
                    mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setText("请输入价格");
                    mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setTextColor(getResources().getColor(R.color.color_C0C4CC));
                }else {
                    mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setEnabled(true);
                    mBinding.ivYijia.setImageResource(R.mipmap.weigouxuan_makeover_publish_price);
                    mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setText("");
                    mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setTextColor(getResources().getColor(R.color.FF000000));
                }
            }
        });

        mBinding.tvFragmentCompanyPublishDeclareDutiableGoodsNormal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isCheck = !isCheck;
                if (isCheck){
                    mBinding.ivTag1.setImageResource(R.mipmap.yigouxuan_makeover_publish);
                    mBinding.ivTag5.setImageResource(R.mipmap.weigouxuan_makeover_publish);
                    isCheckNo = false;
                    mTaxReturns = "1";
                }else {
                    mBinding.ivTag1.setImageResource(R.mipmap.weigouxuan_makeover_publish);
                }
            }
        });

        mBinding.tvFragmentCompanyPublishAutoDeclareDutiableGoodsNonNormal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isCheckNo = !isCheckNo;
                if (isCheckNo){
                    mTaxReturns = "0";
                    mBinding.ivTag5.setImageResource(R.mipmap.yigouxuan_makeover_publish);
                    mBinding.ivTag1.setImageResource(R.mipmap.weigouxuan_makeover_publish);
                    isCheck = false;
                }else {
                    mBinding.ivTag5.setImageResource(R.mipmap.weigouxuan_makeover_publish);
                }
            }
        });
    }

    private void initButton(){
        mBinding.tvFragmentTradePublishSelectType.setOnClickListener(this);
        mBinding.tvFragmentTradePublishSelectIndustry.setOnClickListener(this);
        mBinding.tvFragmentTradePublishSelectCompleteTime.setOnClickListener(this);
        mBinding.tvFragmentTradePublishSelectAddress.setOnClickListener(this);
        mBinding.ivFragmentCompanyPublishUploadPicture.setOnClickListener(this);
        mBinding.tvFragmentTradePublishSelectRate.setOnClickListener(this);
        mBinding.deleteTv.setOnClickListener(this);
    }

    private void initData(){
        if (getArguments() != null){
            mEntity = (PublishCompanyDetailEntity) getArguments().getSerializable("entity");
        }

        if (mEntity!=null){
            mStatus = mEntity.getStatus();
            mId = mEntity.getId()+"";
            mImage = mEntity.getBusinessLicense();
            mTaxReturns = mEntity.getTaxReturns() + "";
            mEnterpriseType = mEntity.getEnterpriseType();
            mIndustry = mEntity.getIndustryType();
            mIndustryName = mEntity.getIndustryName();
            mProvince = mEntity.getAddressPCA(mEntity.getRegisteredAddr()).getProvinceId() + "";
            mProvinceName = mEntity.getAddressPCA(mEntity.getRegisteredAddr()).getProvinceName() + "";
            mCity= mEntity.getAddressPCA(mEntity.getRegisteredAddr()).getCityId() + "";
            mCityName= mEntity.getAddressPCA(mEntity.getRegisteredAddr()).getCityName() + "";
            mArea= mEntity.getAddressPCA(mEntity.getRegisteredAddr()).getAreaId() + "";
            mAreaName= mEntity.getAddressPCA(mEntity.getRegisteredAddr()).getAreaName() + "";
            mTaxScale = mEntity.getTaxScale() + "";
            mCategory = mEntity.getmCategory();
            mCategoryName = mEntity.getmCategoryName();

            mBinding.etFragmentCompanyPublishNameEdit.setText(mEntity.getTransCompanyName());
            mBinding.etFragmentTradePublishCode.setText(mEntity.getSocialCreditCode());
            //0:有限责任公司;1:个人独资公司;2:港澳台公司,3:集团公司
            mBinding.tvFragmentTradePublishSelectType.setText(mEntity.getCompanyType(mEntity.getEnterpriseType()));
            mBinding.tvFragmentTradePublishSelectIndustry.setText(mEntity.getIndustryName());
            mBinding.etFragmentCompanyPublishRegister.setText(PointUtils.price(mEntity.getRegisteredCapital())+"万元");
            mBinding.tvFragmentTradePublishSelectCompleteTime.setText(mEntity.getFoundedDate());
            mBinding.tvFragmentTradePublishSelectAddress.setText(mEntity.getAddress(mEntity.getRegisteredAddr()));
            mBinding.etFragmentTradePublishLinkman.setText(mEntity.getContact());
            mBinding.etFragmentTradePublishPhone.setText(mEntity.getPhone());
            mBinding.etFragmentTradePublishScope.setText(mEntity.getOperatingScope());
            mBinding.tvFragmentCompanyPublishInfo.setText(mEntity.getOtherInfo());
            mBinding.tvFragmentTradePublishSelectRate.setText(mEntity.getTaxType(mEntity.getTaxScale()));
            Glide.with(getContext()).load(mEntity.getBusinessLicense()).apply(new RequestOptions()
                    .placeholder(R.mipmap.makeover_add_picture)
                    .fallback( R.mipmap.makeover_add_picture)
                    .error(R.mipmap.makeover_add_picture)).into(mBinding.ivFragmentCompanyPublishUploadPicture);

            if (mEntity.getTaxReturns() == 1){
                mBinding.ivTag1.setImageResource(R.mipmap.yigouxuan_makeover_publish);
                mBinding.ivTag5.setImageResource(R.mipmap.weigouxuan_makeover_publish);
                isCheckNo = false;
                isCheck = true;
            }else {
                mBinding.ivTag5.setImageResource(R.mipmap.yigouxuan_makeover_publish);
                mBinding.ivTag1.setImageResource(R.mipmap.weigouxuan_makeover_publish);
                isCheck = false;
                isCheckNo = true;
            }

            if (mEntity.getSalePrice() == -1){
                isChecked = true;
                mBinding.ivYijia.setImageResource(R.mipmap.gouxuan_makeover_publish_price);
                mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setEnabled(false);
                mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setText("请输入价格");
                mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setTextColor(getResources().getColor(R.color.color_C0C4CC));
            }else {
                mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setEnabled(true);
                mBinding.ivYijia.setImageResource(R.mipmap.weigouxuan_makeover_publish_price);
                mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setText(PointUtils.originalPrice(mEntity.getSalePrice()));
                mBinding.etFragmentCompanyPublishMakeoverMuchEdit.setTextColor(getResources().getColor(R.color.FF000000));
            }
        }

        mViewModel.getEnterpriseTypeOption();
        mViewModel.getTradeTypeOption(getContext());
        mViewModel.getEnterpriseModelOption();
        mViewModel.getCityList(getContext());

        mViewModel.mEnterpriseTypeListLiveData.observe(getViewLifecycleOwner(), new Observer<List<IpPickSelectEntity>>() {
            @Override
            public void onChanged(List<IpPickSelectEntity> ipPickSelectEntities) {
                if (mEnterpriseTypeOptionsPickerView == null) {
                    mEnterpriseTypeOptionsPickerView = new OptionsPickerBuilder(getContext(), new OnOptionsSelectListener() {
                        @Override
                        public void onOptionsSelect(int options1, int options2, int options3, View v) {
                            mBinding.tvFragmentTradePublishSelectType.setText(ipPickSelectEntities.get(options1).getName());
                            mEnterpriseType = ipPickSelectEntities.get(options1).getValue();
                        }
                    }).setCancelText("取消").setSubCalSize(15)
                            .setCancelColor(Color.parseColor("#666666"))
                            .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                            .setSubmitText("确定")
                            .setSubmitColor(Color.parseColor("#5792FD"))
                            .setTextColorCenter(Color.parseColor("#ff333333"))
                            .setContentTextSize(15)
                            .setLineSpacingMultiplier(2.5f)
                            .setDividerColor(Color.parseColor("#EDEDED"))
                            .setDecorView(getActivity().getWindow().getDecorView().findViewById(android.R.id.content)).build();
                    mEnterpriseTypeOptionsPickerView.setPicker(ipPickSelectEntities);
                    mEnterpriseTypeOptionsPickerView.setSelectOptions(0);
                }
                KeyboardUtils.hideSoftInput(getActivity());
            }
        });

        mViewModel.mIndustryTypeListLiveData.observe(getViewLifecycleOwner(), new Observer<List<IpPickSelectEntity>>() {
            @Override
            public void onChanged(List<IpPickSelectEntity> ipPickSelectEntities) {
                if (mIndustryTypeOptionsPickerView == null) {
                    mIndustryTypeOptionsPickerView = new OptionsPickerBuilder(getContext(), new OnOptionsSelectListener() {
                        @Override
                        public void onOptionsSelect(int options1, int options2, int options3, View v) {
                            mBinding.tvFragmentTradePublishSelectIndustry.setText(ipPickSelectEntities.get(options1).getName());
                            mIndustry = ipPickSelectEntities.get(options1).getId();
                            mIndustryName = ipPickSelectEntities.get(options1).getName();
                        }
                    }).setCancelText("取消").setSubCalSize(15)
                            .setCancelColor(Color.parseColor("#666666"))
                            .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                            .setSubmitText("确定")
                            .setSubmitColor(Color.parseColor("#5792FD"))
                            .setTextColorCenter(Color.parseColor("#ff333333"))
                            .setContentTextSize(15)
                            .setLineSpacingMultiplier(2.5f)
                            .setDividerColor(Color.parseColor("#EDEDED"))
                            .setDecorView(getActivity().getWindow().getDecorView().findViewById(android.R.id.content)).build();
                    mIndustryTypeOptionsPickerView.setPicker(ipPickSelectEntities);
                    mIndustryTypeOptionsPickerView.setSelectOptions(0);
                }
                KeyboardUtils.hideSoftInput(getActivity());
            }
        });

        mViewModel.mAreaLiveData.observe(getViewLifecycleOwner(), new Observer<List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>>>() {
            @Override
            public void onChanged(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntities) {
                if (mCityPickView == null){
                    mCityPickView = new CityPickBuilder(getContext(), new OnOptionsSelectListener() {
                        @Override
                        public void onOptionsSelect(int options1, int options2, int options3, View v) {
                            String areaName;
                            if (addressEntities.get(options1).getChildren().get(options2).getChildren().get(options3) == null) {
                                areaName = "";
                            } else {
                                areaName = addressEntities.get(options1).getChildren().get(options2).getChildren().get(options3).getName();
                                op3 = options3;
                                //区
                                mArea = addressEntities.get(options1).getChildren().get(options2).getChildren().get(options3).getNo();
                                mAreaName = addressEntities.get(options1).getChildren().get(options2).getChildren().get(options3).getName();
                            }
                            String content = addressEntities.get(options1).getName() + "-" + addressEntities.get(options1).getChildren().get(options2).getName() + "-" + areaName;
                            op1 = options1;
                            op2 = options2;
                            //省市
                            mProvince = addressEntities.get(options1).getId();
                            mProvinceName = addressEntities.get(options1).getName();
                            //市
                            mCity = addressEntities.get(options1).getChildren().get(options2).getNo();
                            mCityName = addressEntities.get(options1).getChildren().get(options2).getName();

                            mBinding.tvFragmentTradePublishSelectAddress.setText(content);
                        }
                    }).setCancelText("取消").setSubCalSize(15)
                            .setCancelColor(Color.parseColor("#666666"))
                            .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                            .setSubmitText("确定")
                            .setSubmitColor(Color.parseColor("#5792FD"))
                            .setTextColorCenter(Color.parseColor("#ff333333"))
                            .setContentTextSize(15)
                            .setLineSpacingMultiplier(2.5f)
                            .setDividerColor(Color.parseColor("#EDEDED"))
                            .build();
                    List<List<AddressEntity<List<AddressEntity>>>> city = new ArrayList<>();
                    for (int i = 0; i < addressEntities.size(); i++) {
                        city.add(addressEntities.get(i).getChildren());
                    }

                    List<List<List<AddressEntity>>> area = new ArrayList<>();
                    for (int i = 0; i < addressEntities.size(); i++) {
                        List<List<AddressEntity>> area1 = new ArrayList<>();
                        for (int i1 = 0; i1 < addressEntities.get(i).getChildren().size(); i1++) {
                            area1.add(addressEntities.get(i).getChildren().get(i1).getChildren());
                        }
                        area.add(area1);
                    }

                    mCityPickView.setPicker(addressEntities, city, area);
                    mCityPickView.setSelectOptions(op1, op2, op3);
                }
            }
        });
        mActivity = (MakeOverPublishActivity) getActivity();

        mViewModel.uploadFileSuccess.observe(getViewLifecycleOwner(), new Observer<List<String>>() {
            @Override
            public void onChanged(List<String> list) {
                mImage = list.get(0);
                upload();
            }
        });

        mViewModel.mEnterpriseModelOption.observe(getViewLifecycleOwner(), new Observer<List<IpPickSelectEntity>>() {
            @Override
            public void onChanged(List<IpPickSelectEntity> ipPickSelectEntities) {
                if (mModelOptionsPickerView == null) {
                    mModelOptionsPickerView = new OptionsPickerBuilder(getContext(), new OnOptionsSelectListener() {
                        @Override
                        public void onOptionsSelect(int options1, int options2, int options3, View v) {
                            mBinding.tvFragmentTradePublishSelectRate.setText(ipPickSelectEntities.get(options1).getName());
                            mTaxScale = ipPickSelectEntities.get(options1).getId();
                            mStrTaxReturns = ipPickSelectEntities.get(options1).getName();
                        }
                    }).setCancelText("取消").setSubCalSize(15)
                            .setCancelColor(Color.parseColor("#666666"))
                            .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                            .setSubmitText("确定")
                            .setSubmitColor(Color.parseColor("#5792FD"))
                            .setTextColorCenter(Color.parseColor("#ff333333"))
                            .setContentTextSize(15)
                            .setLineSpacingMultiplier(2.5f)
                            .setDividerColor(Color.parseColor("#EDEDED"))
                            .setDecorView(getActivity().getWindow().getDecorView().findViewById(android.R.id.content)).build();
                    mModelOptionsPickerView.setPicker(ipPickSelectEntities);
                    mModelOptionsPickerView.setSelectOptions(0);
                }
                KeyboardUtils.hideSoftInput(getActivity());
            }
        });

        mViewModel.mSaveSuccessCompany.observe(getViewLifecycleOwner(), new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {
//                getActivity().setResult(2);
                getActivity().finish();
                ActivityJump.jumpToActivity(getContext(), MakeOverPublishMainActivity.class, Pair.create("position", 4));
            }
        });


    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mActivity.mLiveData.observe(getViewLifecycleOwner(), new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {
                if (!UploadCheckHelper.textCheck(getContext(),new TextView[]{mBinding.etFragmentCompanyPublishNameEdit,mBinding.etFragmentTradePublishCode
                                ,mBinding.tvFragmentTradePublishSelectType,mBinding.tvFragmentTradePublishSelectIndustry,mBinding.etFragmentCompanyPublishRegister
                                ,mBinding.tvFragmentTradePublishSelectCompleteTime,mBinding.tvFragmentTradePublishSelectAddress,mBinding.etFragmentCompanyPublishMakeoverMuchEdit
                                ,mBinding.tvFragmentTradePublishSelectRate,mBinding.etFragmentTradePublishLinkman,mBinding.etFragmentTradePublishPhone}
                        ,new String[]{"公司名称","统一社会信用代码","企业类型","行业类型","注册资本","成立日期","注册地址","价格","纳税规模","联系人姓名","联系电话"})){
                    return;
                }
                if (!CheckUtils.isMobileForService(mBinding.etFragmentTradePublishPhone.getText().toString().trim())) {
                    MToast.showToast(getContext(), "请输入正确的电话格式");
                    return;
                }

                if (mImage.equals("") && list.size() <= 0){
                    MToast.showToast(getContext(),"请上传营业执照");
                    return;
                }

                if (mImage.equals("")){
                    mViewModel.uploadPicture(getContext(),list);
                }else {
                    upload();
                }
            }
        });
    }

    private void initFileSelector(){
        PictureSelector.create(this)
                .openGallery(PictureMimeType.ofImage())
                .selectionMode(PictureConfig.SINGLE)
                .compress(true)//是否压缩
                .minimumCompressSize(4 * 1024)//小于4M不压缩
                .maxSelectNum(1)//判断还能选多少张图片
                .forResult(PictureConfig.CHOOSE_REQUEST);

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.tv_fragment_trade_publish_select_type:
                if (mEnterpriseTypeOptionsPickerView != null){
                    mEnterpriseTypeOptionsPickerView.show();
                }else {
                    mViewModel.getEnterpriseTypeOption();
                }
                break;
            case R.id.tv_fragment_trade_publish_select_industry:
                if (mIndustryTypeOptionsPickerView != null){
                    mIndustryTypeOptionsPickerView.show();
                }else {
                    mViewModel.getTradeTypeOption(getContext());
                }
                break;
            case R.id.tv_fragment_trade_publish_select_complete_time:
                PickerHelper.with(getContext()).getCommonTimeBuild("", (date, v1) -> {
                    mTime = DateUtils.getDateTimeFromMillisecond(date.getTime());
                    mBinding.tvFragmentTradePublishSelectCompleteTime.setText(DateUtils.timestampToDate(date.getTime()));
                }).setRangDate(null, Calendar.getInstance()).setCancelText("取消").setSubCalSize(15)
                        .setCancelColor(Color.parseColor("#666666"))
                        .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                        .setSubmitText("确定")
                        .setSubmitColor(Color.parseColor("#5792FD"))
                        .setTextColorCenter(Color.parseColor("#ff333333"))
                        .setContentTextSize(15)
                        .setLineSpacingMultiplier(2.5f)
                        .setDividerColor(Color.parseColor("#EDEDED"))
                        .build().show();
                break;
            case R.id.tv_fragment_trade_publish_select_address:
                if (mCityPickView != null){
                    mCityPickView.show();
                }else {
                    mViewModel.getCityList(getContext());
                }
                break;
            case R.id.iv_fragment_company_publish_upload_picture:
                initFileSelector();
                break;
            case R.id.tv_fragment_trade_publish_select_rate:
                mModelOptionsPickerView.show();
                break;
            case R.id.delete_tv:
                mBinding.ivFragmentCompanyPublishUploadPicture.setImageResource(R.mipmap.makeover_add_picture);
                list.clear();
                break;
        }
    }

    public void upload(){
//        if (!CheckUtils.isMobile(mBinding.etFragmentTradePublishPhone.getText().toString())){
//            MToast.showToast(getContext(),"请输入正确的电话格式");
//            return;
//        }
        /**
         createCom	T文本	是
         （创建企业）

         socialCreditCode	T文本	是
         转让信息中企业名字
         */
        String companyNo = "";
        String teamNo = "";
        String user = "";
        if (SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE,0) == 1){
            companyNo = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.COMPANY_NO,"");
        }else if (SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE,0) == 2){
            teamNo = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.COMPANY_NO,"");
        }else {
            user = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.USER_NO,"");
        }

        Map<String,Object> map = new HashMap<>();
        map.put("id",mId);
        map.put("transCompanyName",mBinding.etFragmentCompanyPublishNameEdit.getText().toString());
        map.put("socialCreditCode",mBinding.etFragmentTradePublishCode.getText().toString());
        map.put("enterpriseType",mEnterpriseType);
        map.put("industryType",mIndustry);
        map.put("industryName",mBinding.tvFragmentTradePublishSelectIndustry.getText().toString());
        map.put("registeredCapital",mBinding.etFragmentCompanyPublishRegister.getText().toString());
        map.put("foundedDate",mTime);
        map.put("registeredAddr",new RegisterAddr().address(new RegisterAddr(Integer.parseInt(mProvince),mProvinceName,Integer.parseInt(mCity),mCityName,Integer.parseInt(mArea),mAreaName)));
        map.put("salePrice",mBinding.etFragmentCompanyPublishMakeoverMuchEdit.getText().toString().equals("请输入价格")?"-1":mBinding.etFragmentCompanyPublishMakeoverMuchEdit.getText().toString());
        map.put("province",mProvince);
        map.put("city",mCity);
        map.put("area",mArea);
        map.put("taxReturns",mTaxReturns);
        map.put("strTaxReturns",mStrTaxReturns);
        map.put("taxScale",mTaxScale);
        map.put("phone",mBinding.etFragmentTradePublishPhone.getText().toString());
        map.put("contact",mBinding.etFragmentTradePublishLinkman.getText().toString());
        map.put("otherInfo",mBinding.tvFragmentCompanyPublishInfo.getText().toString());
        map.put("category",mCategory);
        map.put("categoryName",mCategoryName);
        map.put("companyNo",companyNo);
        map.put("userNo",user);
        map.put("type",SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE,0));
        map.put("userType",SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE,0));
        if (SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE,0) == 0) {
            map.put("realName",SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.REAL_NAME,""));
        } else {
            map.put("realName", SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.COMPANY_NAME, ""));
        }
        map.put("teamNo", teamNo);
        map.put("telPhone",SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LOGIN_PHONE,""));
        map.put("logo",mImage);
        map.put("businessLicense",mImage);
        map.put("status", mStatus);
        map.put("companyName",SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.COMPANY_NAME,""));
        map.put("createCom",companyNo);
        map.put("operatingScope",mBinding.etFragmentTradePublishScope.getText().toString());
        mViewModel.saveAndUpdateCompany(getContext(), map);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PictureConfig.CHOOSE_REQUEST) {
            list.clear();
            List<LocalMedia> imageList = PictureSelector.obtainMultipleResult(data);
            if (imageList == null || imageList.size() == 0) return;
            mImage = "";
            //获取压缩图片
            for (LocalMedia localMedia : imageList) {
                list.add(new File(localMedia.getRealPath()));
            }

            Glide.with(getContext()).load(list.get(0)).into(mBinding.ivFragmentCompanyPublishUploadPicture);
            mBinding.deleteTv.setVisibility(View.VISIBLE);
        }

    }
}
